package binarySearch;

//https://leetcode.cn/problems/find-minimum-in-rotated-sorted-array/description/
public class l_153 {
    public int findMin(int[] nums) {
        if(nums[0] <= nums[nums.length - 1]) return nums[0];
        int left = 0, right = nums.length - 1, x = nums[right];
        //这一题根据mid和数组左右边界的大小比较决定边界移动
        //注意这里不是和二分的左右边界比较大小, 此题右边界可过但左边界不可
        while(left < right)
        {
            int mid = left + (right - left) / 2;
            if(nums[mid] < x) right = mid;
            else left = mid + 1;
        }
        return nums[left];
    }
}
